﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace NeuronDotNet
{
    /// <summary>
    /// This class provides tools to make some calculations 
    /// easier. 
    /// Authors: Savenko Maria, Skorodumov Kirill.
    /// </summary>
    public static class Utils
    {
      /// <summary>
      /// Calculates distance between two points.
      /// </summary>
      /// <returns>Calculated distance.</returns>
      public static double Distance(PointF firstPoint, PointF secondPoint)
      {
          double sqrXDistance = firstPoint.X - secondPoint.X;
          sqrXDistance *= sqrXDistance;

          double sqrYDistance = firstPoint.Y - secondPoint.Y;
          sqrYDistance *= sqrYDistance;

          double sqrDistance = sqrXDistance + sqrYDistance;
          return Math.Sqrt(sqrDistance);
      }

      /// <summary>
      /// Makes two arrays of double from single List of points. Each array for 
      /// one of two coordinates: X or Y.
      /// X coordinates will be under "x" key in result Dictionaty.
      /// Y coordinates will be under "y" key.
      /// </summary>
      /// <param name="pointList">List of points.</param>
      /// <returns>Dictionary with two key-value pairs each for one of
      /// two coordinates: X or Y.</returns>
      public static Dictionary<String, double[]> SeparateIntoCoordinatesArrays(
        List<PointF> pointList)
      {
        //makes two arrays of double values for bridges 
        //points for easier the work with them
        int arraySize = pointList.Count;
        double[] xArray = new double[arraySize];
        double[] yArray = new double[arraySize];
        for (int i = 0; i < arraySize; i++)
        {
          xArray[i] = pointList[i].X;
          yArray[i] = pointList[i].Y;
        }

        Dictionary<String, double[]> result = 
          new Dictionary<string,double[]>();
        result.Add("x", xArray);
        result.Add("y", yArray);

        return result;
      }
    }
}
